<?php

namespace app\adminmini\model;


use think\facade\Db;

class Team extends BaseModel
{
    // 设置数据表名称
    protected $name = "mini_room_list_distribution";


    public function getInfo($id)
    {
        $info = Db::name('mini_room_list_distribution')->where('id', $id)->find();
        $roomlist = Db::name('mini_room_list')->where('id', $info['store_id'])->find();

        $info['referrer'] = '';
        $info['price'] = 0;
        if ($roomlist) {
            $info['referrer'] = $roomlist['room_name'];
            $infoprice = Db::name('distribution_price')->where('store_id', $info['direct_id'])->where('direct_id', $roomlist['id'])->sum('price');
            $info['price'] = $infoprice . '元';
        }
        $info['direct_name'] = '';
        $info['direct_price'] = 0;
        if ($info['indirect_id'] > 0) {


            $roomlist1 = Db::name('mini_room_list')->where('id', $info['indirect_id'])->find();

            if ($roomlist1) {
                $info['direct_name'] = $roomlist1['room_name'];
                $infoprice = Db::name('distribution_price')->where('store_id', $info['indirect_id'])->where('direct_id', $roomlist['id'])->sum('price');


                $info['direct_price'] = $infoprice . '元';

            }
        }


        $info['second_name'] = '';
        $info['level_price'] = 0;
        if ($info['introduction_id'] > 0) {
            $roomlist2 = Db::name('mini_room_list')->where('id', $info['introduction_id'])->find();

            if ($roomlist2) {
                $info['second_name'] = $roomlist2['room_name'];

                $infoprice = Db::name('distribution_price')->where('store_id', $info['introduction_id'])->where('direct_id', $roomlist['id'])->sum('price');


                $info['level_price'] = $infoprice . '元';

            }
        }
        return $info;
    }
}